package com.xuelang.pipeline.artifact.entry.harborv2;

import com.xuelang.pipeline.artifact.app.harborv2.RepositoryService;
import com.xuelang.pipeline.artifact.app.harborv2.request.ListRepositoryQuery;
import com.xuelang.pipeline.artifact.app.harborv2.response.ListRepositoryResponse;
import com.xuelang.pipeline.artifact.app.nexus3v1.xo.ApiResponseXO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * HarborV2 项目下镜像仓库原生接口web服务
 *
 * @author xiwen.zxg
 * @since 2024/7/9
 */
@RestController
@RequestMapping("/repository")
public class RepositoryController {

    @Autowired
    private RepositoryService repositoryService;
    /**
     * 查询项目列表
     *
     * @param projectName
     * @param query
     * @return
     */
    @GetMapping(value = "/projects/{project_name}/repositories", produces = "application/json;charset=utf-8")
    ApiResponseXO<List<ListRepositoryResponse>> listProjectRepository(@PathVariable("project_name") String projectName, @ModelAttribute ListRepositoryQuery query) {
        return repositoryService.listProjectRepository(projectName, query);
    }

    /**
     * 获取单个仓库信息
     *
     * @param projectName
     * @param repositoryName
     * @return
     */
    @GetMapping(value = "/projects/{project_name}/repositories/{repository_name}", produces = "application/json;charset=utf-8")
    ApiResponseXO<ListRepositoryResponse> getProjectRepository(@PathVariable("project_name") String projectName, @PathVariable("repository_name") String repositoryName) {
        return repositoryService.getProjectRepository(projectName, repositoryName);
    }

    /**
     * 删除单个仓库信息
     *
     * @param projectName
     * @param repositoryName
     * @return
     */
    @DeleteMapping(value = "/projects/{project_name}/repositories/{repository_name}", produces = "application/json;charset=utf-8")
    ApiResponseXO<Void> deleteProjectRepository(@PathVariable("project_name") String projectName, @PathVariable("repository_name") String repositoryName) {
        return repositoryService.deleteProjectRepository(projectName, repositoryName);
    }

}
